import router from '@/router';
import { reactive, ref, watch } from 'vue';
import { purmamPage } from '@api/url/test';
import { getInitParam, isNullPm, queryDataFilter } from '@utils/baseMethods';
import { printGroupGetOutsourcing } from '@/api/url/labelPrinting';

export default function importConfig() {
  const base = reactive<any>({
    size: 'medium',
    columns: [
      {
        title: '品名',
        dataIndex: 'articleName',
      },
      {
        title: '料号',
        dataIndex: 'articleNumber',
      },
      {
        title: '单据日期',
        dataIndex: 'documentDate',
      },
      {
        title: '单号',
        dataIndex: 'oddNumber',
      },
      {
        title: '规格',
        dataIndex: 'specification',
      },
      {
        title: '工作中心',
        dataIndex: 'workCenter',
      },
    ],
    config: [],
    pagination: {
      defaultPageSize: 10,
      total: 1, //总条数
      current: 1,
      pageSize: 10,
      showTotal: true,
      showPageSize: true,
      pageSizeOptions: [10, 20, 30, 40, 50],
    },
    editVisible: false,
    showSearchBar: true,
    searchBar: '隐藏搜索',
    rowSelection: {
      type: 'checkbox',
      showCheckedAll: true,
      onlyCurrent: false,
    },
    btns: [
      {
        icon: 'icon-search',
        name: '查询',
      },
      {
        icon: 'icon-refresh',
        name: '重置',
      },
      { icon: '', name: '模板下载' },
      { icon: '', name: '打印' },
      { icon: '', name: '打印(预览)' },
    ],
    data: [],
    collection: [
      {
        label: '打印时机',
        value: '1:物料标签外购',
        key: 'timeNow',
        isSelect: true,
        options: ['1:物料标签外购', '2:物料标签委外', '3:物料标签库存', '4:物料标签退库单', '5:库位标签', '6:物料标签自制'],
      },
      { label: '品名', value: '', key: 'articleName', placeholder: '请输入品名', isInput: true },
      { label: '品号', value: '', key: 'articleNumber', placeholder: '请输入品号', isInput: true },
      { label: '单号', value: '', key: 'oddNumber', placeholder: '请输入单号', isInput: true },
      { label: '规格', value: '', key: 'specification', placeholder: '请输入规格', isInput: true },
      {
        label: '工作中心',
        value: '',
        key: 'workCenter',
        isSelect: true,
        options: ['原材料标签', '期初条码打印模板', '半成品标签', '成品标签'],
      },
    ],
  });

  // watch(() => base.column)
  const opArticleNumber = () => {
    router.push('/numberConfiguration');
  };

  const getTableData = () => {
    // base.pagination.current = 1;
    // base.pagination.pageSize = 10;
    // if (flag == 'search') {
    //   base.pagination.current = 1;
    //   base.pagination.pageSize = 10;
    // }
    // const reqParam = {
    //   page: base.pagination.current,
    //   pageSize: base.pagination.pageSize,
    // };
    const steam = {};
    console.log(base.collection);
    base.collection.forEach((res: any) => {
      if (res.key != 'timeNow') steam[res.key] = res.value;
    });
    console.log(steam);
    printGroupGetOutsourcing(steam).then((res: any) => {
      if (res.code == '200') {
        base.data = res.data;
        base.pagination.total = res.data.length;
      }
    });
    // printGroupGetOutsource
    // printGroupGetInventory
    // printGroupGetMaterialReturnSlip
    // printGroupGetLocationLabel
    // printGroupGetSelfControl
  };

  const init = () => {
    getTableData();
  };

  const handlePageChange = (page: number) => {
    base.pagination.current = page;
  };
  const handlePageSizeChange = (pageSize: number) => {
    base.pagination.pageSize = pageSize;
  };

  const edit = () => {
    base.editVisible = true;
  };

  //控制搜索框的显示与隐藏
  const changeSearchBar = () => {
    base.showSearchBar = !base.showSearchBar;
    if (base.showSearchBar) {
      base.searchBar = '隐藏搜索';
    } else {
      base.searchBar = '显示搜索';
    }
  };

  const tapDate = (param) => {
    base.collection = param;
    init();
  };
  return {
    base,
    opArticleNumber,
    init,
    handlePageChange,
    handlePageSizeChange,
    edit,
    changeSearchBar,
    tapDate,
  };
}
